home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
unlink.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-08
|
885b
|
42 lines
#include <sys/types.h>
#include <sys/syslimits.h>
#include <fcntl.h>
#include "crtlocal.h"
int unlink(const char *path1)
{
long filenum;
int i;
OSErr err;
FileParam pb;
mysleep(1);
pb.ioCompletion = 0;
pb.ioVRefNum = crt_ioVRefNum;
pb.ioFVersNum = 0;
pb.ioFDirIndex = 0;
pb.ioNamePtr = cnv_unix_name(path1);
err = PBGetFInfoSync((ParmBlkPtr)&pb);
if (err) return -1;
filenum = pb.ioFlNum;
for (i = 0; i < OPEN_MAX; i++)
{
if (crt_fd_tab[i].fd && !(crt_fd_tab[i].flags & O_PIPE))
{
FCBPBRec pb;
char name[99];
pb.ioRefNum = crt_fd_tab[i].fd;
pb.ioFCBIndx = 0;
pb.ioCompletion = 0;
pb.ioVRefNum = crt_ioVRefNum;
pb.ioNamePtr = (StringPtr) name;
PBGetFCBInfoSync(&pb);
if (pb.ioFCBFlNm == filenum) /* deleting open file */
{
PBCloseSync((ParmBlkPtr)&pb);
}
}
}
err = PBDeleteSync((ParmBlkPtr)&pb);
return err?-1:0;
}